#include "PlayState.h"

PlayState::PlayState(GameContext& gameC)
	: GameState(gameC)
{
}
PlayState::~PlayState()
{
}
void PlayState::Load()
{
	mMap.Load("level01.txt", "texturepack01.txt");
	mCursor.Load("sword.png");
	char levelName[256];
	char textureName[256];
	sprintf_s(levelName, 256, "level0%d.txt", mGameContext.GetLevel());
	sprintf_s(textureName, 256, "Texturepack0%d.txt", mGameContext.GetLevel());

}
void PlayState::Unload()
{
	mMap.Unload();
	mCursor.Unload();
}
NextStates PlayState::Update(float deltaTime)
{
	mCursor.Update(deltaTime);
	NextStates nextState = None;
	if(Input_IsKeyPressed(Keys::ESCAPE))
	{
		nextState = Frontend;
	}
	return nextState;
}
void PlayState::Render()
{
	const int kWinWidth = IniFile_GetInt("WinWidth",800);
	const int kWinHeight = IniFile_GetInt("WinHeight",800);

	SVector2 viewTarget((float)Input_GetMouseScreenX(), (float)Input_GetMouseScreenY());
	SVector2 viewOffset;
	viewOffset.x = viewTarget.x - (kWinWidth*0.5f);
	viewOffset.y = viewTarget.y - (kWinHeight*0.5f);

	SVector2 limit;
	limit.x = (float)mMap.getWidth2D() - kWinWidth/2;
	limit.y = (float)mMap.getHeight2D() - kWinHeight/2;

	viewOffset.x = Clamp(viewOffset.x, 0.0f, limit.x);
	viewOffset.y = Clamp(viewOffset.y, 0.0f, limit.y);
	mMap.Render(viewOffset);
	mCursor.Render();
}